package com.education.expenses.assembler;

import com.education.expenses.common.dto.UserProfileDTO;
import com.education.expenses.entity.Role;
import com.education.expenses.entity.User;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * User: Alex Kasianik
 * Date: 20.08.12
 * Time: 4:34
 */
@Component
public class UserProfileAssembler extends GenericAssembler<User, UserProfileDTO>{
    @Override
    public UserProfileDTO toDTO(User entity) {
        UserProfileDTO dto = new UserProfileDTO();
        dto.setEmail(entity.getEmail());
        dto.setName(entity.getSurname() + ", " + entity.getFirstname());
        dto.setId(entity.getId());
        if (entity.getRole() == Role.USER_ROLE){
            dto.setApprover(false);
        }
        else {
            dto.setApprover(true);
        }
        return dto;
    }

    public List<UserProfileDTO> toListDTO(List<User> users){
        List<UserProfileDTO> list = new ArrayList<UserProfileDTO>();
        for(User user: users){
            list.add(toDTO(user));
        }
        return list;
    }
}
